package com.example.order.controller;


//import com.example.PaymentServiceApi;

import com.example.PaymentServiceApi;
import com.example.ResultVO;
import com.example.ccp.starter.utils.UserContextUtil;
import com.example.order.dao.CourseDao;
import com.example.order.po.Course;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * OrderController.java
 */
@RestController
@Slf4j
@RequestMapping("/api")
public class OrderController {
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Resource
    private PaymentServiceApi payment;

    @Resource
    private RestTemplate restTemplate;

    @Autowired
    private CourseDao courseDao;


    @GetMapping(value = "/create/{id}")
    public ResultVO createOrder(@PathVariable("id") Integer id) {
        log.info("queryUser the current user:");
        //String result = payment.payment(id);
        String result = restTemplate.getForObject("http://payment-service/payment/pay/11", String.class);
        return new ResultVO<>(result);
    }

    @GetMapping(value = "/query/{id}")
    public ResultVO queryOrder(@PathVariable("id") Integer id) {
        //String result = payment.payment(id);
        //return new ResultVO<>(result);
        return new ResultVO<>(1111111111);
    }

    @GetMapping("/queryAllCourse")
    private ResultVO queryAllCourse() {
        List<Course> list = courseDao.queryAllCourse();
        return new ResultVO<>(list);
    }

    @PostMapping("/saveCourse")
    private ResultVO saveCourse(@RequestBody @Valid Course course) {
        courseDao.saveCourse(course);
        return new ResultVO<>();
    }
}